<template>
  <el-dialog
     v-drag
    :title="!dataForm.takingId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<el-form-item label="盘点日期" prop="takingDate">
  <el-input size="mini"  v-model="dataForm.takingDate" placeholder="盘点日期" clearable></el-input>
</el-form-item>
<el-form-item label="产品id" prop="productId">
  <el-input size="mini"  v-model="dataForm.productId" placeholder="产品id" clearable></el-input>
</el-form-item>
<el-form-item label="产品编码" prop="productCode">
  <el-input size="mini"  v-model="dataForm.productCode" placeholder="产品编码" clearable></el-input>
</el-form-item>
<el-form-item label="产品名称" prop="productName">
  <el-input size="mini"  v-model="dataForm.productName" placeholder="产品名称" clearable></el-input>
</el-form-item>
<el-form-item label="条形码" prop="barCode">
  <el-input size="mini"  v-model="dataForm.barCode" placeholder="条形码" clearable></el-input>
</el-form-item>
<el-form-item label="批号" prop="batchNo">
  <el-input size="mini"  v-model="dataForm.batchNo" placeholder="批号" clearable></el-input>
</el-form-item>
<el-form-item label="规格" prop="standard">
  <el-input size="mini"  v-model="dataForm.standard" placeholder="规格" clearable></el-input>
</el-form-item>
<el-form-item label="单位" prop="unit">
  <el-input size="mini"  v-model="dataForm.unit" placeholder="单位" clearable></el-input>
</el-form-item>
<el-form-item label="厂家" prop="produceFactory">
  <el-input size="mini"  v-model="dataForm.produceFactory" placeholder="厂家" clearable></el-input>
</el-form-item>
<el-form-item label="产地" prop="producingArea">
  <el-input size="mini"  v-model="dataForm.producingArea" placeholder="产地" clearable></el-input>
</el-form-item>
<el-form-item label="批发价" prop="tradePrice">
  <el-input size="mini"  v-model="dataForm.tradePrice" placeholder="批发价" clearable></el-input>
</el-form-item>
<el-form-item label="生产日期" prop="produceDate">
  <el-input size="mini"  v-model="dataForm.produceDate" placeholder="生产日期" clearable></el-input>
</el-form-item>
<el-form-item label="有效期" prop="expiryDate">
  <el-input size="mini"  v-model="dataForm.expiryDate" placeholder="有效期" clearable></el-input>
</el-form-item>
<el-form-item label="通用名" prop="genericName">
  <el-input size="mini"  v-model="dataForm.genericName" placeholder="通用名" clearable></el-input>
</el-form-item>
<el-form-item label="批准文号" prop="approvalNo">
  <el-input size="mini"  v-model="dataForm.approvalNo" placeholder="批准文号" clearable></el-input>
</el-form-item>
<el-form-item label="剂型" prop="dosageForm">
  <el-input size="mini"  v-model="dataForm.dosageForm" placeholder="剂型" clearable></el-input>
</el-form-item>
<el-form-item label="批次号" prop="lotNo">
  <el-input size="mini"  v-model="dataForm.lotNo" placeholder="批次号" clearable></el-input>
</el-form-item>
<el-form-item label="账面数量" prop="bookCount">
  <el-input size="mini"  v-model="dataForm.bookCount" placeholder="账面数量" clearable></el-input>
</el-form-item>
<el-form-item label="账面金额" prop="bookFee">
  <el-input size="mini"  v-model="dataForm.bookFee" placeholder="账面金额" clearable></el-input>
</el-form-item>
<el-form-item label="盘点数量" prop="checkCount">
  <el-input size="mini"  v-model="dataForm.checkCount" placeholder="盘点数量" clearable></el-input>
</el-form-item>
<el-form-item label="盘点金额" prop="checkFee">
  <el-input size="mini"  v-model="dataForm.checkFee" placeholder="盘点金额" clearable></el-input>
</el-form-item>
<el-form-item label="损益数量" prop="profitAndLossCount">
  <el-input size="mini"  v-model="dataForm.profitAndLossCount" placeholder="损益数量" clearable></el-input>
</el-form-item>
<el-form-item label="损益金额" prop="profitAndLossFee">
  <el-input size="mini"  v-model="dataForm.profitAndLossFee" placeholder="损益金额" clearable></el-input>
</el-form-item>
<el-form-item label="审核状态" prop="auditStatus">
  <el-input size="mini"  v-model="dataForm.auditStatus" placeholder="审核状态" clearable></el-input>
</el-form-item>
<el-form-item label="审核人id" prop="auditorId">
  <el-input size="mini"  v-model="dataForm.auditorId" placeholder="审核人id" clearable></el-input>
</el-form-item>
<el-form-item label="审核人" prop="auditor">
  <el-input size="mini"  v-model="dataForm.auditor" placeholder="审核人" clearable></el-input>
</el-form-item>
<el-form-item label="审核说明" prop="auditNote">
  <el-input size="mini"  v-model="dataForm.auditNote" placeholder="审核说明" clearable></el-input>
</el-form-item>
<el-form-item label="门店id" prop="storeId">
  <el-input size="mini"  v-model="dataForm.storeId" placeholder="门店id" clearable></el-input>
</el-form-item>
<el-form-item label="门店名称" prop="storeName">
  <el-input size="mini"  v-model="dataForm.storeName" placeholder="门店名称" clearable></el-input>
</el-form-item>
<el-form-item label="门店编码" prop="storeCode">
  <el-input size="mini"  v-model="dataForm.storeCode" placeholder="门店编码" clearable></el-input>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
  <el-input size="mini"  v-model="dataForm.createTime" placeholder="创建时间" clearable></el-input>
</el-form-item>
<el-form-item label="修改时间" prop="updateTime">
  <el-input size="mini"  v-model="dataForm.updateTime" placeholder="修改时间" clearable></el-input>
</el-form-item>
<el-form-item label="创建人" prop="createUsername">
  <el-input size="mini"  v-model="dataForm.createUsername" placeholder="创建人" clearable></el-input>
</el-form-item>
<el-form-item label="创建人id" prop="createUserId">
  <el-input size="mini"  v-model="dataForm.createUserId" placeholder="创建人id" clearable></el-input>
</el-form-item>
<el-form-item label="修改人" prop="updateUsername">
  <el-input size="mini"  v-model="dataForm.updateUsername" placeholder="修改人" clearable></el-input>
</el-form-item>
<el-form-item label="修改人id" prop="updateUserId">
  <el-input size="mini"  v-model="dataForm.updateUserId" placeholder="修改人id" clearable></el-input>
</el-form-item>
<el-form-item label="是否可用 1:是" prop="status">
  <el-input size="mini"  v-model="dataForm.status" placeholder="是否可用 1:是" clearable></el-input>
</el-form-item>
<el-form-item label="版本" prop="version">
  <el-input size="mini"  v-model="dataForm.version" placeholder="版本" clearable></el-input>
</el-form-item>
<el-form-item label="是否删除 1:是" prop="isDeleted">
  <el-input size="mini"  v-model="dataForm.isDeleted" placeholder="是否删除 1:是" clearable></el-input>
</el-form-item>
<el-form-item label="备注" prop="remark">
  <el-input size="mini"  v-model="dataForm.remark" placeholder="备注" clearable></el-input>
</el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          takingId: 0,
          takingDate: '',
          productId: '',
          productCode: '',
          productName: '',
          barCode: '',
          batchNo: '',
          standard: '',
          unit: '',
          produceFactory: '',
          producingArea: '',
          tradePrice: '',
          produceDate: '',
          expiryDate: '',
          genericName: '',
          approvalNo: '',
          dosageForm: '',
          lotNo: '',
          bookCount: '',
          bookFee: '',
          checkCount: '',
          checkFee: '',
          profitAndLossCount: '',
          profitAndLossFee: '',
          auditStatus: '',
          auditorId: '',
          auditor: '',
          auditNote: '',
          storeId: '',
          storeName: '',
          storeCode: '',
          createTime: '',
          updateTime: '',
          createUsername: '',
          createUserId: '',
          updateUsername: '',
          updateUserId: '',
          status: '',
          version: '',
          isDeleted: '',
          remark: ''
        },
        dataRule: {
          takingDate: [
            { required: true, message: '盘点日期不能为空', trigger: 'blur' }
          ],
          productId: [
            { required: true, message: '产品id不能为空', trigger: 'blur' }
          ],
          productCode: [
            { required: true, message: '产品编码不能为空', trigger: 'blur' }
          ],
          productName: [
            { required: true, message: '产品名称不能为空', trigger: 'blur' }
          ],
          barCode: [
            { required: true, message: '条形码不能为空', trigger: 'blur' }
          ],
          batchNo: [
            { required: true, message: '批号不能为空', trigger: 'blur' }
          ],
          standard: [
            { required: true, message: '规格不能为空', trigger: 'blur' }
          ],
          unit: [
            { required: true, message: '单位不能为空', trigger: 'blur' }
          ],
          produceFactory: [
            { required: true, message: '厂家不能为空', trigger: 'blur' }
          ],
          producingArea: [
            { required: true, message: '产地不能为空', trigger: 'blur' }
          ],
          tradePrice: [
            { required: true, message: '批发价不能为空', trigger: 'blur' }
          ],
          produceDate: [
            { required: true, message: '生产日期不能为空', trigger: 'blur' }
          ],
          expiryDate: [
            { required: true, message: '有效期不能为空', trigger: 'blur' }
          ],
          genericName: [
            { required: true, message: '通用名不能为空', trigger: 'blur' }
          ],
          approvalNo: [
            { required: true, message: '批准文号不能为空', trigger: 'blur' }
          ],
          dosageForm: [
            { required: true, message: '剂型不能为空', trigger: 'blur' }
          ],
          lotNo: [
            { required: true, message: '批次号不能为空', trigger: 'blur' }
          ],
          bookCount: [
            { required: true, message: '账面数量不能为空', trigger: 'blur' }
          ],
          bookFee: [
            { required: true, message: '账面金额不能为空', trigger: 'blur' }
          ],
          checkCount: [
            { required: true, message: '盘点数量不能为空', trigger: 'blur' }
          ],
          checkFee: [
            { required: true, message: '盘点金额不能为空', trigger: 'blur' }
          ],
          profitAndLossCount: [
            { required: true, message: '损益数量不能为空', trigger: 'blur' }
          ],
          profitAndLossFee: [
            { required: true, message: '损益金额不能为空', trigger: 'blur' }
          ],
          auditStatus: [
            { required: true, message: '审核状态不能为空', trigger: 'blur' }
          ],
          auditorId: [
            { required: true, message: '审核人id不能为空', trigger: 'blur' }
          ],
          auditor: [
            { required: true, message: '审核人不能为空', trigger: 'blur' }
          ],
          auditNote: [
            { required: true, message: '审核说明不能为空', trigger: 'blur' }
          ],
          storeId: [
            { required: true, message: '门店id不能为空', trigger: 'blur' }
          ],
          storeName: [
            { required: true, message: '门店名称不能为空', trigger: 'blur' }
          ],
          storeCode: [
            { required: true, message: '门店编码不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          createUsername: [
            { required: true, message: '创建人不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '创建人id不能为空', trigger: 'blur' }
          ],
          updateUsername: [
            { required: true, message: '修改人不能为空', trigger: 'blur' }
          ],
          updateUserId: [
            { required: true, message: '修改人id不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '是否可用 1:是不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除 1:是不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.takingId = id || 0
        this.visible = true
        this.$nextTick(async () => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.takingId) {
            const res = await this.$http({
              url: `/stock/stocktaking/info/${this.dataForm.takingId}`,
              method: 'get',
              params: this.$http.adornParams()
            })
                let data = res.data
                if (data && data.code === 0) {
                    this.dataForm = data.stockTaking
                }
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate(async (valid) => {
          if (valid) {
            const res = await this.$http({
              url:`/stock/stocktaking/${!this.dataForm.takingId ? 'save' : 'update'}`,
              method: 'post',
             data: this.$http.adornData( this.dataForm)
            })
            let data = res.data
            if (data && data.code === 0) {
                this.$message({
                        message: '操作成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                }
            })
            } else {
                this.$message.error(data.msg)
            }
          }
        })
      }
    }
  }
</script>
